//
//  NSArray+WLBlock.h
//  CeXi
//
//  Created by 王亮 on 2017/7/12.
//  Copyright © 2017年 wangLiang. All rights reserved.
//

#import "NSArray+WLBlock.h"

@implementation NSArray (WLBlock)


- (void)each_wl:(void (^)(id object))block {
    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        block(obj);
    }];
}

- (void)eachWithIndex_wl:(void (^)(id object, NSUInteger index))block {
    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        block(obj, idx);
    }];
}

- (BOOL)isSubsetSanArr_wl:(NSArray*)sanArr{
    NSSet *set1 = [NSSet setWithArray:self];
    NSSet *set2 = [NSSet setWithArray:sanArr];
    
    if ([set2 isSubsetOfSet:set1]) {
        return YES;
    }
    else {
        return NO;
    }
}


///冒泡排序
- (NSArray *)changeList_wl{
    NSMutableArray *array = [self copy];
    if (array.count > 1) {
        for (int  i =0; i<[array count]-1; i++) {
            for (int j = i+1; j<[array count]; j++) {
                if ([array[i] intValue]>[array[j] intValue]) {
                    //交换
                    [array exchangeObjectAtIndex:i withObjectAtIndex:j];
                }
            }
        }
    }
    NSArray * resultArray = [[NSArray alloc]initWithArray:array];
    return resultArray;
}
@end
